{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "f5a66d42",
   "metadata": {},
   "source": [
    "# 920课堂内容"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "d341133d",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_01_name = \"Maarry\"\n",
    "# 思考：如果想一个变量存放一个班同学的名字，该怎么存？\n",
    "# 思考：处理书记会不会比较麻烦"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "ad72a1a1",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Marry,Alex,Jack,张三\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = \"Marry,Alex,Jack,张三\"\n",
    "print(网三_name_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "15fe8175",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Alex'"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思考2：处理数据会不会比较麻烦？\n",
    "网三_name_list[6:10]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "09af6fe8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "18"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 这个名单有多少人名\n",
    "len(网三_name_list)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e681df13",
   "metadata": {},
   "source": [
    "## 引入列表的概念\n",
    " * list可以放数值和字符，但是通常要么一起放数值，要么一起放字符串\n",
    " "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "42f348b3",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1, 2, 3, 4] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "a = [1,2,3,4]\n",
    "print(a,type(a))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "97eccd3b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "['Marry', 'Alex', 'Jack', 'zhangsan'] <class 'list'>\n"
     ]
    }
   ],
   "source": [
    "网三_name_list = [\"Marry\",\"Alex\",\"Jack\",\"zhangsan\"]\n",
    "print(网三_name_list,type(网三_name_list))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "ac62e401",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Marry'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list[0] # 去除 网三_name_list 中第一位同学的名字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "f6ab7c1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "网三： 李华\n",
      "网三： 李华\n",
      "网三： Alex\n",
      "网三： Jack\n",
      "网三： zhangsan\n",
      "网三： 李四\n",
      "网三： 李四\n",
      "网三： 四\n",
      "网三： 5\n"
     ]
    }
   ],
   "source": [
    "for i in 网三_name_list:\n",
    "    print(\"网三：\",i)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "311d4a61",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.append(\"5\") # append在末尾增加"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "6b10a69f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李华', '李华', 'Alex', 'Jack', 'zhangsan', '李四', '李四', '四', '5']"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "0ec852e2",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function insert:\n",
      "\n",
      "insert(index, object, /) method of builtins.list instance\n",
      "    Insert object before index.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.insert)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7a2cff40",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.insert(1,\"李华\") # insert 插入"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "814e574b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李华', '李华', 'Alex', 'Jack', 'zhangsan', '李四', '李四', '四', '5']"
      ]
     },
     "execution_count": 33,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "8194760c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function remove:\n",
      "\n",
      "remove(value, /) method of builtins.list instance\n",
      "    Remove first occurrence of value.\n",
      "    \n",
      "    Raises ValueError if the value is not present.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(网三_name_list.remove)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "6c0a9ff8",
   "metadata": {},
   "outputs": [],
   "source": [
    "网三_name_list.remove(\"Marry\")"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "id": "8f2572bf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['李华', '李华', 'Alex', 'Jack', 'zhangsan', '李四', '李四']"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "网三_name_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "1c4b3c63",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list = [18,19,23,17,18,18,19,19,15,11] #实践：移除19的元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "b6b0b86f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "age_list.count(19)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "5677ea0b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[18, 23, 17, 18, 18, 15, 11]"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路一:remove,先决条件，知道值出现的次数\n",
    "删除的数量 = age_list.count(19)\n",
    "for i in range(删除的数量):\n",
    "    if 19 in age_list:\n",
    "        age_list.remove(19)\n",
    "    age_list\n",
    "age_list\n",
    "    "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "id": "e58e0091",
   "metadata": {},
   "outputs": [],
   "source": [
    "age_list = [18,19,23,17,18,18,19,19,15,11]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "id": "c1283faf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 19\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "[18, 23, 17, 18, 18, 15, 11]"
      ]
     },
     "execution_count": 54,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# 思路热二：pop(index),先决条件，知道值出现的位置\n",
    "for i,v in enumerate(age_list):\n",
    "    if v == 19:\n",
    "        print(i,v)\n",
    "        age_list.pop(i)\n",
    "age_list"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "4b4cf6bb",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on built-in function pop:\n",
      "\n",
      "pop(index=-1, /) method of builtins.list instance\n",
      "    Remove and return item at index (default last).\n",
      "    \n",
      "    Raises IndexError if list is empty or index is out of range.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(age_list.pop)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "e3a911ed",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on class enumerate in module builtins:\n",
      "\n",
      "class enumerate(object)\n",
      " |  enumerate(iterable, start=0)\n",
      " |  \n",
      " |  Return an enumerate object.\n",
      " |  \n",
      " |    iterable\n",
      " |      an object supporting iteration\n",
      " |  \n",
      " |  The enumerate object yields pairs containing a count (from start, which\n",
      " |  defaults to zero) and a value yielded by the iterable argument.\n",
      " |  \n",
      " |  enumerate is useful for obtaining an indexed list:\n",
      " |      (0, seq[0]), (1, seq[1]), (2, seq[2]), ...\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __iter__(self, /)\n",
      " |      Implement iter(self).\n",
      " |  \n",
      " |  __next__(self, /)\n",
      " |      Implement next(self).\n",
      " |  \n",
      " |  __reduce__(...)\n",
      " |      Return state information for pickling.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods defined here:\n",
      " |  \n",
      " |  __class_getitem__(...) from builtins.type\n",
      " |      See PEP 585\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(enumerate)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f061b551",
   "metadata": {},
   "source": [
    "# 课后练习：81，68课本"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "69ec3c2c",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
